/*!
 * @Author: luoob
 * @Date: 2021-03-29 21:59:00
 * @Last Modified by: luoob
 * @Last Modified time: 2021-03-29 21:59:00
 * @Instruduction: 工具函数库
 */

import _ from 'lodash'

/**
 * 生成随机字符串
 * @date 2021-04-01
 * @param {number} len
 * @returns {any}
 */
export const createRandomString = (len: number = 16) => {
    const charSet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
    return _.sampleSize(charSet, len).toString().replace(/,/g, '')
}

/**
 * 生成字节大小, 单位字节
 * @date 2021-04-13
 * @returns {any}
 */
export const createSize = ({ size, type }: { size: number; type: 'MB' | 'KB' | 'BYTE' }) => {
    switch (type) {
        case 'MB':
            return Math.pow(1024, 2) * size
        case 'KB':
            return Math.pow(1024, 1) * size
        case 'BYTE':
            return size
    }
}

/**
 * 创建对应版本 url 路径，用于做本地代理
 * 添加 url 前缀
 * @date 2021-07-05
 * @param {any} prefix:string
 * @param {any} url:string
 * @returns {any}
 */
export const createPrefixPath = (prefix: string, url: string) => {
    return prefix + url
}
